package com.storm.queue.core

import com.storm.queue.register.AbstractTopicRegister
import org.springframework.beans.BeansException
import org.springframework.boot.ApplicationArguments
import org.springframework.boot.ApplicationRunner
import org.springframework.context.ApplicationContext
import org.springframework.context.ApplicationContextAware

var applicationContext:ApplicationContext? = null

class QueueRun(private val delayQueueContext: DelayQueueContext):ApplicationRunner, ApplicationContextAware{
    override fun run(args: ApplicationArguments) {
        if (applicationContext != null) {
            val beansOfType = applicationContext?.getBeansOfType(AbstractTopicRegister::class.java)
            if (beansOfType != null) {
                for((k, v) in beansOfType){
                    delayQueueContext.addTopicRegister(v)
                }

            }
            delayQueueContext.init()
        }
    }
    override fun setApplicationContext(p0: ApplicationContext) {
        applicationContext = p0
    }
}